package tr.edu.ege.kipler.satisfiability.blocking;

import java.util.Iterator;

import tr.edu.ege.kipler.satisfiability.container.ABox;
import tr.edu.ege.kipler.satisfiability.container.Individual;
import tr.edu.ege.kipler.satisfiability.container.SHIQABox;
import tr.edu.ege.kipler.satisfiability.container.operational.IndividualNameComparator;

/**
 * 
 * @author İnanç Seylan
 *
 */
public class SubsetBlocking implements BlockingStrategy {

	public boolean isIndirectlyBlocked(ABox abox, String indvName) {
		return false;
	}

	public boolean isBlocked(ABox abox, String indvName) {
		SHIQABox shiqABox = (SHIQABox) abox;
		Individual indv = shiqABox.getIndividual(indvName);
		return !shiqABox.isRoot(indv)
				&& isBlockingConditionSatisfied(abox, indv);
	}

	private boolean isBlockingConditionSatisfied(ABox abox, Individual x) {
		boolean result = false;
		IndividualNameComparator comparator = new IndividualNameComparator(
				(SHIQABox) abox);
		// TODO: find some quicker method instead of whole individual iteration
		Iterator<Individual> i = abox.individualIterator();
		while (i.hasNext() && !result) {
			Individual xAncestor = i.next();
			if (comparator.compare(xAncestor, x) < 0
					&& xAncestor.containsAllConceptsOf(x)) {
				result = true;
			}
		}
		return result;
	}

}
